<?php
namespace app\admin\controller;
use think\Controller;
use app\model\Useradmin;
use think\Db;
use think\Session;
class Login extends controller
{   


    public function login()
    {   
        return $this->fetch();
    }

    public function index(){
  
       $shuyzm=strtolower(input('post.capital'));
       session_start();
       $setyzm=strtolower($_SESSION['yzm']);

       if($shuyzm==$setyzm){
            $username = input('post.username');
            $password = input('post.password');
            $info = Db::query("select * from user where user_name='$username' and user_password='$password' ");
          
            if($info){
                echo "1";      //有这个人的信息
                $time=time();
                $uid=$info[0]['user_id'];
                Db::execute("update user set user_lastlogintime='$time' where user_id=$uid  ");
                $_SESSION['userid']= $info[0]['user_id'];
                $_SESSION['username']= $info[0]['user_name'];

            }else{  
                echo "0";         //没有这个人的信息
            } 

       }else{
           echo "2";              //验证验证码
       }
        
    }

    public function back(){
        session_start();
        session_destroy();
        $this->error('退出成功','admin/Login/login'); 
    }

   
}